home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / json / tool.pyc (.txt) < prev   
Python Compiled Bytecode  |  2014-12-31  |  1KB  |  45 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Command-line tool to validate and pretty-print JSON
  5.  
  6. Usage::
  7.  
  8.     $ echo \'{"json":"obj"}\' | python -m json.tool
  9.     {
  10.         "json": "obj"
  11.     }
  12.     $ echo \'{ 1.2:3.4}\' | python -m json.tool
  13.     Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
  14.  
  15. '''
  16. import sys
  17. import json
  18.  
  19. def main():
  20.     if len(sys.argv) == 1:
  21.         infile = sys.stdin
  22.         outfile = sys.stdout
  23.     elif len(sys.argv) == 2:
  24.         infile = open(sys.argv[1], 'rb')
  25.         outfile = sys.stdout
  26.     elif len(sys.argv) == 3:
  27.         infile = open(sys.argv[1], 'rb')
  28.         outfile = open(sys.argv[2], 'wb')
  29.     else:
  30.         raise SystemExit(sys.argv[0] + ' [infile [outfile]]')
  31.     with None:
  32.         
  33.         try:
  34.             obj = json.load(infile)
  35.         except ValueError:
  36.             e = None
  37.             raise SystemExit(e)
  38.  
  39.     with outfile:
  40.         json.dump(obj, outfile, sort_keys = True, indent = 4, separators = (',', ': '))
  41.         outfile.write('\n')
  42.  
  43. if __name__ == '__main__':
  44.     main()
  45.